package com.yix.controller;

import com.yix.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/db")
public class DBController {
    @Autowired
    private UserService userService;

    @GetMapping("/table-exists")
    public String checkTableExists(@RequestParam String tableName) {
        boolean exists = userService.isTableExists(tableName);
        return "Table " + tableName + " exists: " + exists;
    }

    @PostMapping("/create-table")
    public String createTable() {
        userService.createTable();
        return "Table created successfully";
    }

    @PostMapping("/drop-table")
    public String dropTable(@RequestParam String tableName) {
        userService.dropTable(tableName);
        return "Table " + tableName + " dropped successfully";
    }
}
